angular.module('mamApp').controller('cpNewAddedController', ['$scope', 'DataManager', '$state','api','paramsManager',
    function ($scope, DataManager, $state,api,paramsManager) {
        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            startTime: $state.params.startTime || "",
            endTime: $state.params.endTime || "",
            "X-Auth-Token": $scope.userInfo.token
        }


        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }


        $scope.rangeDate = {
            startDate: $scope.search.startTime ? moment($scope.search.startTime).format('X') : null,
            endDate: $scope.search.endTime ? moment($scope.search.endTime).format('X') : null,
            onSelected: function (data, scope) {  //时间选择确认事件
                $scope.search.startTime = data.startDate ? moment(new Date(parseFloat(data.startDate) * 1000)).format("YYYY-MM-DD") : null;
                $scope.search.endTime = data.endDate ? moment(new Date(new Date(parseFloat(data.endDate) * 1000))).format("YYYY-MM-DD") : null;
                $scope.search.pageNo=1;
                $state.go($state.current.name, $scope.search);

            }
        };

        $scope.noPermission=false;
        $scope.dateShow=false;



        if($scope.search.startTime!==""){
            $scope.downHref=api+"/admin/exportNewCpCount"+paramsManager.query($scope.search);
            DataManager.cpNewAddedCountStat([$scope.search.pageNo,$scope.search.pageSize],$scope.search).then(function (result) {
                if(result.data.c=="n"){
                    $scope.noPermission=true;
                    return false;
                }
                $scope.list=result.data.pageList;
                var list = angular.copy($scope.list).reverse();
                console.log(list)
                var xAxisData = [];
                var data1 = [];
                var data2 = [];
                var data3 = [];
                var data4 = [];
                var data5 = [];
                var data6 = [];
                var data7 = [];
                var data8 = [];
                var data9 = [];
                var data10 = [];
                var data11 = [];
                var data12 = [];
                list.forEach(function (item) {
                    xAxisData.push(item.countTime);
                    data1.push(item.cpNum);
                    data2.push(item.lvOneNum);
                    data3.push(item.lvTwoNum);
                    data4.push(item.lvThreeNum);
                    data5.push(item.reviewWatingNum);
                    data6.push(item.reviewFailNum);
                    data7.push(item.reviewPassNum);
                    data8.push(item.statusNotEnableNum);
                    data9.push(item.statusForbidNum);
                    data10.push(item.statusEnableNum);
                    data11.push(item.coopTypeSignedNum);
                    data12.push(item.coopTypeNotSignedNum);
                })
                var seriesData = [data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12];
                initData(xAxisData, seriesData);
                $scope.paginationConf.totalItems=result.data.total;
            })
        }else{
            $scope.downHref=api+"/admin/exportNewCpCount/month"+paramsManager.query($scope.search);
            DataManager.cpNewAddedMonthCountStat([$scope.search.pageNo,$scope.search.pageSize],$scope.search).then(function (result) {
                if(result.data.c=="n"){
                    $scope.noPermission=true;
                    return false;
                }
                $scope.list=result.data.pageList;
                var list = angular.copy($scope.list).reverse();
                console.log(list)
                var xAxisData = [];
                var data1 = [];
                var data2 = [];
                var data3 = [];
                var data4 = [];
                var data5 = [];
                var data6 = [];
                var data7 = [];
                var data8 = [];
                var data9 = [];
                var data10 = [];
                var data11 = [];
                var data12 = [];
                list.forEach(function (item) {
                    xAxisData.push(item.countTime);
                    data1.push(item.cpNum);
                    data2.push(item.lvOneNum);
                    data3.push(item.lvTwoNum);
                    data4.push(item.lvThreeNum);
                    data5.push(item.reviewWatingNum);
                    data6.push(item.reviewFailNum);
                    data7.push(item.reviewPassNum);
                    data8.push(item.statusNotEnableNum);
                    data9.push(item.statusForbidNum);
                    data10.push(item.statusEnableNum);
                    data11.push(item.coopTypeSignedNum);
                    data12.push(item.coopTypeNotSignedNum);
                })
                var seriesData = [data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12];
                initData(xAxisData, seriesData);
                $scope.paginationConf.totalItems=result.data.total;
            })

        }

        function initData(xAxisData, seriesData) {
           
            $scope.option = {
                title: {
                    text: 'CP新增'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                legend: {
                    data: ['CP新增', 'LV1', 'LV2', 'LV3', '认证-待审核', '认证-未通过', '认证-通过', '功能-待启用', '功能-禁用', '功能-启用', '已签约', '未签约'],
                    bottom:"-5"
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '6%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: xAxisData
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: 'CP新增',
                        type: 'line',
                        data: seriesData[0]
                    },
                    {
                        name: 'LV1',
                        type: 'line',
                        data: seriesData[1]
                    },
                    {
                        name: 'LV2',
                        type: 'line',
                        stack: 'CP等级',
                        data: seriesData[2]
                    },
                    {
                        name: 'LV3',
                        type: 'line',
                        data: seriesData[3]
                    },
                    {
                        name: '认证-待审核',
                        type: 'line',
                        data: seriesData[4],

                    },
                    {
                        name: '认证-未通过',
                        type: 'line',
                        data: seriesData[5]
                    },
                    {
                        name: '认证-通过',
                        type: 'line',
                        data: seriesData[6]
                    },
                    {
                        name: '功能-待启用',
                        type: 'line',
                        data: seriesData[7]
                    },
                    {
                        name: '功能-禁用',
                        type: 'line',
                        data: seriesData[8]
                    },
                    {
                        name: '功能-启用',
                        type: 'line',
                        data: seriesData[9]
                    },
                    {
                        name: '已签约',
                        type: 'line',
                        data: seriesData[10]
                    },
                    {
                        name: '未签约',
                        type: 'line',
                        data: seriesData[11]
                    }
                ]
            };
        }


        function albumDataInit(data) {
            console.log(data)
            $scope.albumOption = {
                title: {
                    text: ' 专辑审核',
                    x: 'center',
                    textStyle:{
                        fontSize:16,
                        fontWeight:500,
                        color:'#000',
                        fontFamily:'Microsoft Yahei',
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['已通过', '未通过', '待审核']
                },
                series: [
                    {
                        name: '专辑审核',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data,

                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        color:['#7797BC', '#F9C84C','#FF2840']
                    }
                ]
            };
        }


    }])

